package www.wackyboy.top.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import www.wackyboy.top.Employee;
import www.wackyboy.top.UserLogin;
import www.wackyboy.top.dao.IUserDao;
import www.wackyboy.top.service.IUserService;

import java.util.List;

/**
 * @Author: WackyBoy
 * @Date: 2021/1/5 15:52
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserDao userDao;

    @Override
    public List<Employee> queryAllInfo() {
        return this.userDao.queryAllInfo();
    }

    @Override
    public Integer saveUserInfo(Employee employee) {
        return this.userDao.saveUserInfo(employee);
    }

    @Override
    public Integer addUserInfo(Employee employee) { return this.userDao.addUserInfo(employee);}

    @Override
    public Integer deleteUserInfo(Integer id) {return this.userDao.deleteUserInfo(id); }

    @Override
    public List<Employee>  searchUserInfo(String name) { return this.userDao.searchUserInfo("%" + name + "%"); }

    @Override
    public Integer deleteUserByBatch(List<Integer> idList) {
        int flag = 0;
        for(int i = 0; i < idList.size(); i++) {
            Integer id = idList.get(i);
            Integer integer = this.userDao.deleteUserByBatch(id);
            if(integer == 0) flag++;
        }
        return flag;
    }

    @Override
    public Employee checkUserInfo(UserLogin user) {

        return this.userDao.checkUserInfo(user);
    }


}
